﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace doxyOutParser.CodeCheck
{
	public class Uv2IncludeDirsParser : IIncludeDirsParser
	{
		private string _uv2projectFile;
		public Uv2IncludeDirsParser(string uv2projectFile)
		{
			//TODO Check the value of string and eventually check if exist or not.
			this._uv2projectFile = uv2projectFile;
		}


		#region IIncludeDirsParser Members

		public string[] GetIncludeDirsTable()
		{
			// Using of StreamReader to parse the file
			StreamReader uv2ProjectStreamReader = new StreamReader(this._uv2projectFile);
			string line = uv2ProjectStreamReader.ReadLine();
			string[] dirsSeparators = { ";" };

			while (line != null)
			{
				if (line.Contains("ADSCINCD"))
				{
					int startIndex = line.IndexOf("(");
					int endIndex = line.IndexOf(")");
					if (startIndex != 0 && endIndex != 0)
					{
						string includeDirsData = line.Substring(startIndex + 1, (endIndex - startIndex-1));
						uv2ProjectStreamReader.Close();
						return includeDirsData.Split(dirsSeparators,StringSplitOptions.RemoveEmptyEntries);
					}
				}
				// Read Next Line
				line = uv2ProjectStreamReader.ReadLine();
			}
			return null;
		}

		#endregion

	}
}
